{% extends 'base.html' %}
{% block title %}
  用户信息修改
{% endblock %}
{% block newcontent %}
    <h1>用户信息更新</h1>
    <p style="color: red">{{ msg }}</p>
    <form action="{{ url_for('user.update') }}" method="post">
        <input type="hidden" name="id" value="{{ user.id }}">
        <p><input type="text" name="username" placeholder="用户名" value="{{ user.username }}"></p>
        <p><input type="number" id="InputPhone" name="phone" placeholder="电话" value="{{ user.phone }}"><span></span></p>
        <p><input type="submit" value="用户更新"></p>
    </form>
{% endblock %}

{% block scripts %}
    {{ super() }}
    <script>
        $('#InputPhone').blur(function(){
            let phone = $(this).val();
            let span_ele = $(this).next('span');
            if(phone.length == 11){
                span_ele.text('');
                $.get('{{ url_for('user.check_phone') }}', {phone:phone}, function(data){
                   // console.log(data);
                    if(data.code!=200) {
                        span_ele.css({"color":"#ff0011"});
                        span_ele.text(data.msg);
                    }
            })}
            else{
                span_ele.css({"color":"#ff0011"});
                span_ele.text('手机格式错误');
            }
        })
    </script>
{% endblock %}